﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.LogEntries.TakePrisonerLogEntry
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.LogEntries
{
  public class TakePrisonerLogEntry : LogEntry, IEncyclopediaLog, IChatNotification, IWarLog
  {
    [SaveableField(330)]
    public readonly IFaction CapturerPartyMapFaction;
    [SaveableField(331)]
    public readonly Hero Prisoner;
    [SaveableField(332)]
    public readonly Settlement CapturerSettlement;
    [SaveableField(333)]
    public readonly Hero CapturerMobilePartyLeader;
    [SaveableField(334)]
    public readonly Hero CapturerHero;

    internal static void AutoGeneratedStaticCollectObjectsTakePrisonerLogEntry(
      object o,
      List<object> collectedObjects)
    {
      ((LogEntry) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this.CapturerPartyMapFaction);
      collectedObjects.Add((object) this.Prisoner);
      collectedObjects.Add((object) this.CapturerSettlement);
      collectedObjects.Add((object) this.CapturerMobilePartyLeader);
      collectedObjects.Add((object) this.CapturerHero);
    }

    internal static object AutoGeneratedGetMemberValueCapturerPartyMapFaction(object o)
    {
      return (object) ((TakePrisonerLogEntry) o).CapturerPartyMapFaction;
    }

    internal static object AutoGeneratedGetMemberValuePrisoner(object o)
    {
      return (object) ((TakePrisonerLogEntry) o).Prisoner;
    }

    internal static object AutoGeneratedGetMemberValueCapturerSettlement(object o)
    {
      return (object) ((TakePrisonerLogEntry) o).CapturerSettlement;
    }

    internal static object AutoGeneratedGetMemberValueCapturerMobilePartyLeader(object o)
    {
      return (object) ((TakePrisonerLogEntry) o).CapturerMobilePartyLeader;
    }

    internal static object AutoGeneratedGetMemberValueCapturerHero(object o)
    {
      return (object) ((TakePrisonerLogEntry) o).CapturerHero;
    }

    public override CampaignTime KeepInHistoryTime => CampaignTime.Weeks(12f);

    public bool IsVisibleNotification => true;

    public override ChatNotificationType NotificationType
    {
      get
      {
        return this.MilitaryNotification((IFaction) this.CapturerHero?.Clan ?? this.CapturerPartyMapFaction, (IFaction) this.Prisoner.Clan);
      }
    }

    public TakePrisonerLogEntry(PartyBase capturerParty, Hero prisoner)
    {
      this.CapturerPartyMapFaction = capturerParty.MapFaction;
      this.CapturerHero = capturerParty.LeaderHero;
      this.CapturerMobilePartyLeader = capturerParty.MobileParty?.LeaderHero;
      this.CapturerSettlement = capturerParty.Settlement;
      this.Prisoner = prisoner;
    }

    public bool IsRelatedToWar(StanceLink stance, out IFaction effector, out IFaction effected)
    {
      IFaction faction1 = stance.Faction1;
      IFaction faction2 = stance.Faction2;
      effector = this.CapturerPartyMapFaction.MapFaction;
      effected = this.Prisoner.MapFaction;
      if (this.CapturerPartyMapFaction == faction1 && this.Prisoner.MapFaction == faction2)
        return true;
      return this.CapturerPartyMapFaction == faction2 && this.Prisoner.MapFaction == faction1;
    }

    public override string ToString() => this.GetNotificationText().ToString();

    public TextObject GetNotificationText()
    {
      TextObject parent = new TextObject("{=QRJQ9Wgv}{PRISONER_LORD.LINK}{?PRISONER_LORD_HAS_FACTION_LINK} of the {PRISONER_LORD_FACTION_LINK}{?}{\\?} has been taken prisoner by the {CAPTOR_FACTION}.");
      if (this.CapturerHero != null)
      {
        parent = new TextObject("{=Ebb7aH3T}{PRISONER_LORD.LINK}{?PRISONER_LORD_HAS_FACTION_LINK} of the {PRISONER_LORD_FACTION_LINK}{?}{\\?} has been taken prisoner by {CAPTURER_LORD.LINK}{?CAPTURER_LORD_HAS_FACTION_LINK} of the {CAPTURER_LORD_FACTION_LINK}{?}{\\?}.");
        StringHelpers.SetCharacterProperties("CAPTURER_LORD", this.CapturerHero.CharacterObject, parent);
        Clan clan = this.CapturerHero.Clan;
        if ((clan != null ? (!clan.IsMinorFaction ? 1 : 0) : 0) != 0)
        {
          parent.SetTextVariable("CAPTURER_LORD_FACTION_LINK", this.CapturerHero.MapFaction.EncyclopediaLinkWithName);
          parent.SetTextVariable("CAPTURER_LORD_HAS_FACTION_LINK", 1);
        }
      }
      parent.SetTextVariable("CAPTOR_FACTION", this.CapturerPartyMapFaction.InformalName);
      StringHelpers.SetCharacterProperties("PRISONER_LORD", this.Prisoner.CharacterObject, parent);
      Clan clan1 = this.Prisoner.Clan;
      if ((clan1 != null ? (!clan1.IsMinorFaction ? 1 : 0) : 0) != 0)
      {
        parent.SetTextVariable("PRISONER_LORD_FACTION_LINK", this.Prisoner.MapFaction.EncyclopediaLinkWithName);
        parent.SetTextVariable("PRISONER_LORD_HAS_FACTION_LINK", 1);
      }
      return parent;
    }

    public bool IsVisibleInEncyclopediaPageOf<T>(T obj) where T : MBObjectBase
    {
      if ((object) obj == this.Prisoner || this.CapturerSettlement != null && (object) obj == this.CapturerSettlement)
        return true;
      return this.CapturerMobilePartyLeader != null && (object) obj == this.CapturerMobilePartyLeader;
    }

    public TextObject GetEncyclopediaText() => this.GetNotificationText();
  }
}
